﻿using System;
using System.Collections.Generic;
using System.Linq;
using Fortune.Attributes.API;

namespace Fortune.API
{
    /// <summary>
    /// 获取游戏内当前宇宙的全部恒星
    /// </summary>
    [RequestMapping("/galaxy/star/_realTime")]
    public class GalaxyApi : AbstractApi<object>
    {
        protected override object handle(object param)
        {
            return toSerializableList(GameMain.galaxy.stars);
        }
        
        private static List<Dictionary<string, object>> toSerializableList(IEnumerable<StarData> stars)
        {
            return stars.Select(star => new Dictionary<string, object>()
                {
                    {"age", star.age},
                    {"color", star.color},
                    {"seed", star.seed},
                    {"id", star.id},
                    {"index", star.index},
                    {"level", star.level},
                    {"lifetime", star.lifetime},
                    {"loaded", star.loaded},
                    {"luminosity", star.luminosity},
                    {"mass", star.mass},
                    {"name", star.name},
                    {"position", $"{star.position.x},{star.position.y},{star.position.z}"},
                    {"radius", star.radius},
                    {"spectrType", Enum.GetName(typeof(ESpectrType), star.spectr)},
                    {"starType", Enum.GetName(typeof(EStarType), star.type)},
                    {"temperature", star.temperature},
                    {"acdiskRadius", star.acdiskRadius},
                    {"classFactor", star.classFactor},
                    {"displayName", star.displayName},
                    {"dysonLumino", star.dysonLumino},
                    {"habitableRadius", star.habitableRadius},
                    {"dysonRadius", star.dysonRadius},
                    {"orbitScaler", star.orbitScaler},
                    {"asterBelt1OrbitIndex", star.asterBelt1OrbitIndex},
                    {"asterBelt2OrbitIndex", star.asterBelt2OrbitIndex},
                    {"asterBelt1Radius", star.asterBelt1Radius},
                    {"asterBelt2Radius", star.asterBelt2Radius},
                    {"planetCount", star.planetCount},
                    {"resourceCoef", star.resourceCoef},
                    {"kEnterDistance", StarData.kEnterDistance},
                    {"kPhysicsRadiusRatio", StarData.kPhysicsRadiusRatio},
                    {"kViewRadiusRatio", StarData.kViewRadiusRatio},
                    {"systemRadius", star.systemRadius},
                    {"physicsRadius", star.physicsRadius},
                    {"viewRadius", star.viewRadius},
                    {"typeString", star.typeString},
                }
            ).ToList();
        }
    }
}